import java.util.ArrayDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-12
 * Time: 16:14
 */
public class MyQueueUseStack {
    //这里我用ArrayDeque来当作栈
    public ArrayDeque<Integer> s1;
    public ArrayDeque<Integer> s2;

    public MyQueueUseStack() {
        s1=new ArrayDeque<>();
        s2=new ArrayDeque<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if(empty()) {
            return -1;
        }
        if(s2.isEmpty()) {
            //第一个栈里面所有的元素 放到第二个栈当中
            while(!s1.isEmpty()) {
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if(empty()) {
            return -1;
        }
        if(s2.isEmpty()) {
            //第一个栈里面所有的元素 放到第二个栈当中
            while(!s1.isEmpty()) {
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty()&&s2.isEmpty();
    }
}
